import logging
import time
import unittest

from webAutomation import utils
from webAutomation.page.login_page import LoginProxy
from webAutomation.utils import DriverUtil


class TestLogin(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.login_proxy = LoginProxy()

    @classmethod
    def tearDown(self) -> None:
        DriverUtil.quit_driver()

    def test01_login_success(self, username="admin", password="123"):
        try:

            # 输出日志
            logging.info("当前登录的用户名：{}".format(username))
            # 登录
            self.login_proxy.login(username, password)
            time.sleep(2)
            # 断言
            assert_result = utils.exit_text("今日新增注册用户")
            print(assert_result)
            self.assertTrue(assert_result)

        # 捕捉异常
        except Exception as e:
            # 截图
            utils.screenshot(self)
            # 输出日志
            logging.info("登录出现异常：{}".format(e))
            raise

        finally:
            print("----------login end...-----------")
